/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package projetlif13.model.tictactoe;

import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
import projetlif13.model.Board;
import projetlif13.model.HumanPlayer;
import projetlif13.model.Move;
import projetlif13.model.puissance4.HPlayerP4;
import projetlif13.scene.GameScene;

/**
 *
 * @author theo
 */
public class HPlayerTic extends HumanPlayer {

    public HPlayerTic(String name) {
        super(name);
    }

    @Override
    public Move getMove(Board _board) {
        boolean canreturn = false;
        Move m = null;
        while (!canreturn) {
            HumanPlayer.canPlay = true;
            while (GameScene.cmde.equals("") || GameScene.cmde.length() < 4) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException ex) {
                    Logger.getLogger(HPlayerP4.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            //format x,y
            System.out.println(GameScene.cmde);
            StringTokenizer st = new StringTokenizer(GameScene.cmde);
            int x = Integer.parseInt(st.nextToken(","));
            int y = Integer.parseInt(st.nextToken(","));
            GameScene.cmde = "";
            m = new TicMove(x, y);
            canreturn = GameScene.gv.getGame().moveAvailable(m);
        }
        return m;
    }
}
